<?php

namespace App\Console\Commands;

use App\Models\InvestmentMeeting;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class FinishMeetingCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'finish:meeting';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '定时结束报名';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $lists = InvestmentMeeting::query()->where('status', 1)->whereNotNull('end_time')->where('end_time', '<', date('Y-m-d H:i:s'))->get();
        foreach ($lists as $item) {
            $item->status = -1;
            $item->save();
        }
        $lists = InvestmentMeeting::query()->where('status', 0)->whereNotNull('start_time')->where('start_time', '<', date('Y-m-d H:i:s'))->get();
        foreach ($lists as $item) {
            $item->status = 1;
            $item->save();
        }
        Log::info('定时开启结束报名成功');
        return Command::SUCCESS;
    }
}
